;(function ($) {
    //httpClient
    // 初始化页面数据
   var initData = function () {
       $.ajax({
           url:"http://localhost:8080/goods",
           type:"GET",
           dataType:"JSON",
           success:function (res) {
               var size = res.size;
               var datas = res.datas;
               console.log(datas)
               //生成对应的数据
               var str=''
               for (var i in datas) {
                   str+=` <div class="col-md-3">
                    <a href="single.html?good_id=${datas[i].good_id}">
                        <div class="thumbnail" lang="${datas[i].good_id}">
                            <img src="img/${datas[i].good_img_pos}" alt="">
                            <h6>${datas[i].sku_title}</h6>
                        </div>
                    </a>
                </div>`
               }
               $(".shop-list").empty().append(str)
               //console.log(s)
           }
       })
   }
   initData()

    $("a").click(function () {
        // 获取用户点击的商品信息
        var good_info = $(this).attr("lang");
        // 获取用户当前系统时间
        var user_time = func_time();
        // 获取用户浏览器信息
        var browse_info = JSON.stringify($.support);
        // 获取用户的信息
        var ui = window.sessionStorage.getItem("custom");
        // 获取用户的秘钥信息
        var user_info = ui==null?"10000":ui;

        $.ajax({
            url:"http://localhost:8080/customAct",
            data:{act:"COLLECT "+user_time+" "+user_info+" "+good_info+" "+browse_info},
            type:"POST"
        })
    })

    function func_time() {
        var date = new Date()
        return date.getFullYear()+"-"+timeformat(date.getMonth()+1)+"-"+
            timeformat(date.getDate())+"T" +timeformat(date.getHours())+":"+
            timeformat(date.getMinutes())+":"+timeformat(date.getSeconds())+"."+
            date.getMilliseconds()
    }
    function timeformat(time) {
        if ((time+"").length<=1){
            return "0"+time
        }else{
            return time
        }
    }
})(jQuery);

;(function ($) {
    function func_time() {
        var date = new Date()
        return date.getFullYear() + "-" + timeformat(date.getMonth() + 1) + "-" +
            timeformat(date.getDate()) + "T" + timeformat(date.getHours()) + ":" +
            timeformat(date.getMinutes()) + ":" + timeformat(date.getSeconds()) + "." +
            date.getMilliseconds()
    }

    function timeformat(time) {
        if ((time + "").length <= 1) {
            return "0" + time
        } else {
            return time
        }
    }

    var initData = function () {
        $.ajax({
            url: "http://localhost:8080/goods",
            type: "GET",
            dataType: "JSON",
            success: function (res) {
                var datas = res.datas;
                for (var i in datas) {
                    // 获取用户点击的商品信息
                    var good_info = datas[i].good_id;
                    // 获取用户当前系统时间
                    var user_time = func_time();
                    // 获取用户浏览器信息
                    var browse_info = JSON.stringify($.support);
                    // 获取用户的信息
                    var ui = window.sessionStorage.getItem("custom");
                    // 获取用户的秘钥信息
                    var user_info = ui == null ? "10000" : ui;

                    $.ajax({
                        url: "http://localhost:8080/customAct",
                        data: {act: "BROWSE " + user_time + " " + user_info + " " + good_info + " " + browse_info},
                        type: "POST"
                    })
                }
            }
        })
    }
    initData()
})(jQuery);


